Have you ever had a program crash the system?
Yes.
On 1950's mainframes and even many 1990's PCs a single input mistake could cause the entire computer system to stop dead (a "crash"). Programs were written with the unreasonable expectation that all input data would be correct and would be read in successfully.
Java is an industrial-strength programming language,
and is designed to help the programmer
deal with bad data and the all-too-common input failures.
When an input or an output operation fails,
an exception is generated.
An exception is an object (a chunk of main memory) that contains
information about what went wrong.
The section of code where the problem occurred can deal with the
problem itself,
or pass the exception on.
Passing the exception on is called throwing an exception.
The phrase throws IOException
in:
public static void main (String[] args) throws IOException
. . .means that the part of the system that started main()
must be
prepared to deal with an IO exception.
For us,
all this means is that the program will be halted gracefully.